new Vue({
  el: '#app',
  data: function () {
    return {
      indexPage: {
        search: {
          page: 1,
          limit: 50,
          下辖ID: '',
          所属事业部: '',
          下辖ID归属人: '',
          开始时间: '',
          结束时间: ''
        },
        total: 0,
        tableData: [],
        loadingFlag: false
      },
    }
  },
  mounted() {
    this.list();
  },
  methods: {
    pageChange(val) {
      this.indexPage.search.page = val
      this.list()
    },

    searchBtn() {
      this.indexPage.search.page = 1
      this.list()
    },
    handleSizeChange(val) {
      this.indexPage.search.limit = val;
      this.list();
    },
    list() {
      let params = this.indexPage.search;
      axios.get('/pageList', {params: params}).then(res => {
        console.log(res.data.data);
        var result = res.data;
        if (result.code == 0) {
          this.indexPage.tableData = result.data.records;
          this.indexPage.total = result.data.total;
        }

      });

    },

    parseAlotOfFileBtn: function () {
      const loading = this.$loading({
        lock: true,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
        text: '读取文件解析中......',
        customClass: 'IZAYAMask'
      });
      axios.get('/get').then(res => {
        let data = res.data;
        if (data.code === 0) {
          setTimeout(this.getParseExcelResult(this, loading), 3000);
        } else {
          this.$message.warning("文件解析出现异常");
        }

      })

    },

    getParseExcelResult(_this, load) {
      axios.get('getResult').then(res => {
        console.log(res);
        if (res.data.data === 0) {
          setTimeout(_this.$options.methods.getParseExcelResult(_this, load), 3000);
        } else if (res.data.data === 2) {
          _this.$options.methods.method2(_this, load);
        } else {
          load.close();
          _this.$message.success("文件操作完成");
        }

      })

    },

    method2(_this, load) {
      axios.get('getResult1', {responseType: 'blob'}).then(res => {
        _this.$message.error("有数据重复正在生成excel");
        const link = document.createElement('a');
        let blob = new Blob([res.data], {type: 'application/vnd.ms-excel'});
        link.style.display = 'none';
        link.href = URL.createObjectURL(blob);
        let date = new Date();
        link.download = '重复id详情.xlsx';  // 下载名称
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        _this.$message.success("导出成功");
        load.close()
      })
    },

    parseAlotOfFileBtnSecond() {
      const loading = this.$loading({
        lock: true,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)',
        text: '读取文件解析中.......',
        customClass: 'IZAYAMask'
      }); //点击第二次解析按钮弹出正在加载遮罩层
      console.log("进入1");
      axios.get('/again').then(() => {   //请求'/again接口'console.log("发送again请求");
        setTimeout(this.getParseExcelResultSecond(this, loading), 3000) //3秒后调用getParseExcelResultSecond方法

      });
    },
    getParseExcelResultSecond(_this, load) {
      console.log("进入12");
      axios.get('/fileGetResult').then(res => {  //请求'fileGetResult'接口
            console.log(res);
            if (res.data.data === 0) {  //如果返回的数据里面的data字段为 0
              setTimeout(
                  _this.$options.methods.getParseExcelResultSecond(_this, load), 3000); //3秒后调用本身这个方法
            } else if (res.data.data === 2) {  //如果返回的数据里面的data字段为 1
              console.log("进入1234");
              _this.$options.methods.method3(_this, load); //调用method3
            } else {  //当成功的获取解析结果
              load.close();  //关闭正在加载
              _this.$message.warning(res.data.msg);
            }
          }
      )
    },
    method3(_this, load) {
      console.log("进入123");
      debugger;
      axios.get('filegetResult1', {responseType: 'blob'}).then(res => {//请求'filegetResult1'接口,返回类型是'blob'
        _this.$message.error("有数据重复正在生成excel");
        const link = document.createElement('a');
        let blob = new Blob([res.data], {type: 'application/vnd.ms-excel'});
        link.style.display = 'none';
        link.href = URL.createObjectURL(blob);
        let date = new Date();
        link.download = '重复id详情.xlsx';  // 下载名称
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        _this.$message.success("导出成功");
        load.close()
      });
    },
  }
})